/**
 * Created by fangjiahui on 15/12/9.
 * Count Down
 */

//need jquery
// 所有模块都通过 define 来定义
define(function (require, exports, module) {

    // 通过 require 引入依赖
    //默认配置


    var options = {
        type: 0,
        shade: 0.3,
        fix: true,
        title: '&#x4FE1;&#x606F;',
        offset: 'auto',
        area: 'auto',
        closeBtn: 1,
        time: 0, //0表示不自动关闭
        zIndex: 19891014,
        maxWidth: 360,
        shift: 0,
        icon: -1,
        scrollbar: true, //是否允许浏览器滚动条
        tips: 2
    };

    var Model = {
        _options: options,
        showMsg: function (data, okLink, falseLink) {
            //TODO Pour future utiliser
            if (data.result == true || data.resCode == '1') {
                layer.open($.extend(this._options,
                    {
                        icon: 1,
                        content: data.msg || data.resMsg || '请求成功',
                    },
                    (function () {
                        if (okLink) {
                            return {
                                btn: [okLink.name],
                                btn1: function (index, layero) {
                                    window.location.href = okLink.link;
                                }
                            }
                        } else {
                            return {};
                        }
                    })()
                ));
                return true;
            }
            else {

                layer.open($.extend(this._options,
                    {
                        icon: 2,
                        content: data.msg || data.resMsg || '请求失败',
                    },
                    (function () {
                        if (falseLink) {
                            return {
                                btn: [falseLink.name],
                                btn1: function (index, layero) {
                                    window.location.href = falseLink.link;
                                }
                            }
                        } else {
                            return {};
                        }
                    })()
                ));
                return false;
            }
        },
    }


    // 通过 exports 对外提供接口
    //exports.doSomething = ...

    // 或者通过 module.exports 提供整个接口
    module.exports = Model;

});